#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=150;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[200000];
LL c[maxn][maxn],dis[maxn][maxn];
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL n;cin>>n;
   for(LL i=1;i<=n;i++) {
        cin>>a[i];
        if(a[i]==0){
            i--;n--;
        }
   }
   if(n>128){
      cout<<"3"<<"\n";
      return 0;
   }
   LL ans=0x3f3f3f3f;
   for(LL i=1;i<=n;i++){
      for(LL j=1;j<=n;j++){
         if( (a[i]&a[j])&&(i!=j)) c[i][j]=dis[i][j]=1;
         else c[i][j]=dis[i][j]=0x3f3f3f3f;
      }
   }
   for(LL k=1;k<=n;k++){
      for(LL i=1;i<=k-1;i++){
        for(LL j=i+1;j<=k-1;j++){
            ans=min(ans,dis[i][j]+c[i][k]+c[k][j]);
        }
      }
      for(LL i=1;i<=n;i++){
        for(LL j=1;j<=n;j++){
            dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
        }
      }
   }
   if(ans==0x3f3f3f3f) cout<<"-1"<<"\n";
   else cout<<ans<<"\n";
   return 0;
}
